﻿Namespace AboutDNN.DNNMVC

    ''' <summary>
    ''' This class represents the route information of controller and action
    ''' </summary>
    Public Class RouteInfo
        Public Controller As String
        Public Action As String

        Public Shared Function DefaultRoute() As RouteInfo
            Return New RouteInfo With {.Controller = "Home", .Action = "Default"}
        End Function

        Public Shared Function GetFromUrl(ByVal request As IRequest) As RouteInfo
            Dim ri = New RouteInfo
            ri.Controller = IIf(request.QueryString(Params.Controller) Is Nothing, "Home", request.QueryString(Params.Controller))
            ri.Action = IIf(request.QueryString(Params.Action) Is Nothing, "Default", request.QueryString(Params.Action))
            Return ri
        End Function

        Public Function GetUrl() As String
            Dim querystring = ""
            For Each key As String In App.MVCContext.QueryString.Keys
                If key <> Params.Controller AndAlso key <> Params.Action Then
                    querystring += "&" & key & "=" & App.MVCContext.QueryString(key)
                End If
            Next
            Return App.ClientUrl(Action, Controller, querystring)
        End Function
    End Class

End Namespace
